package cn.com.fuhuitong.main.home.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import cn.com.fuhuitong.app.BaseApplication
import cn.com.fuhuitong.base.BaseViewModel
import cn.com.fuhuitong.http.HttpResponse
import cn.com.fuhuitong.http.ViewModelSubscribeListener
import cn.com.fuhuitong.main.home.entity.MemberResponse
import cn.com.fuhuitong.main.home.mode.HomeManager
import cn.com.fuhuitong.main.host.entity.ConfigResponse
import io.reactivex.disposables.Disposable

class MemberViewModel(application: Application) : BaseViewModel(application) {
    private val homeManager: HomeManager = HomeManager()

    val memberDataLiveData = MutableLiveData<HttpResponse<MemberResponse>>()

    val configDataLiveData = MutableLiveData<HttpResponse<ConfigResponse>>()


    /**
     * 获取会员列表
     * */
    fun memberList() {
        val listener =
            object : ViewModelSubscribeListener<MemberResponse>(memberDataLiveData) {}
        val memberItemDisposable: Disposable = homeManager.memberList(
            BaseApplication.userToken(), listener
        )
        dispose.add(memberItemDisposable)
    }

    /**
     * 获取指定会员
     * */
    fun memberItem(id: Int) {
        val listener =
            object : ViewModelSubscribeListener<MemberResponse>(memberDataLiveData) {}
        val memberItemDisposable: Disposable = homeManager.memberItem(
            BaseApplication.userToken(), id.toString(), listener
        )
        dispose.add(memberItemDisposable)
    }



    /**
     * 获取配置信息
     * */
    fun configValue(name: Array<String>) {
        val listener =
            object : ViewModelSubscribeListener<ConfigResponse>(configDataLiveData) {}
        val configValueDisposable: Disposable = homeManager.configValue(name,listener)
        dispose.add(configValueDisposable)
    }
}